/*
 * This file is part of AudioStream.
 * Copyright (C) 2010 Justin Li and Jacob Wirth
 *
 *  AudioStream is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AudioStream is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AudioStream.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */

import java.io.IOException;
import java.util.Scanner;

import org.frustra.audiostream.AudioStreamConnection;

/**
 * The purpose of this class is to provide an example usage of the AudioStream library
 *
 */

public class ExampleStreamer {
	
	/**
	 * Runs a command and gets the output
	 * @param command
	 * @return
	 * @throws IOException
	 */
	public static String run(String command) throws IOException {
		Process p = Runtime.getRuntime().exec(command);
		Scanner scan = new Scanner(p.getInputStream());
		return scan.nextLine();
	}
	
	public static void main() {
		
		AudioStreamConnection client = new AudioStreamConnection("localhost", 8000, "listen") {
			public String getNextSong() throws Exception {
				//return run("someCommand"); // Use to run a command and get the output (string path to mp3 file)
				return "foobar.mp3";
			}
		};
		
		client.setName("AudioStream Example Stream");
		client.setDescription("A test of the AudioStream streaming library");
		client.setGenre("Folk");
		client.setURL("http://frustra.org:8000/listen"); 
		client.setUsername("source");
		client.setPassword("hackme");
		
		try {
			client.connect();
			client.startStream();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
